import { root } from "../apiRoot";
import { defHttp } from '@/utils/http';
import { IQuery, IResData } from "../types";
import { KnowledgeBaseFileDetailResult, KnowledgeBaseFileListResult, KnowledgeBaseFileSetting, KnowledgeBaseFileShareListData, KnowledgeBaseFileShareListResult, MemberInfoResult } from "./types";

const Api = {
  knowledgeBaseFileList: root + 'bot/file/getList',
  knowledgeBaseFileSave: root + 'bot/file/save',
  knowledgeBaseFileDelete: root + 'bot/file/deleteFile',
  knowledgeBaseFileDetail: root + 'bot/file/getInfo',
  knowledgeBaseFileSetting: root + 'bot/file/saveFileSetting',
  knowledgeBaseFileShareList: root + 'bot/file/shareList',

  getAttachmentIds: root + 'bot/getAttachmentIds',
  getMemberInfo: root + 'bot/org/getInfo', // 获取会员信息
  setEnable: root + 'bot/org/setEnable', // 设置启用或禁用
}


/**
 * @description 获取知识库文件列表
 * @date 06/03/2025
 * @export
 */
export function knowledgeBaseFileList(data: IQuery) {
  return defHttp.post<IResData<KnowledgeBaseFileListResult>>({
    url: Api.knowledgeBaseFileList,
    data,
  });
}

/**
 * @description 上传知识库文件
 * @date 07/03/2025
 * @export
 * @param {{ path: string, name: string, size: number }} data
 */
export function knowledgeBaseFileSave(data: { path: string, name: string, size: number }) {
  return defHttp.files({
    url: Api.knowledgeBaseFileSave,
    files: {
      path: data.path,
      size: data.size,
    },
    name: 'file',
    formData: {
      fileName: data.name,
    }
  }, {
    disableLoading: true
  });
}

/**
 * @description 删除知识库文件
 * @date 07/03/2025
 * @export
 */
export function knowledgeBaseFileDelete(data: { id: number }) {
  return defHttp.post({
    url: Api.knowledgeBaseFileDelete,
    data,
  });
}

/**
 * @description 获取知识库文件详情
 * @date 10/03/2025
 * @export
 */
export function knowledgeBaseFileDetail(data: { id: number }) {
  return defHttp.post<KnowledgeBaseFileDetailResult>({
    url: Api.knowledgeBaseFileDetail,
    data,
  });
}

/**
 * @description 保存知识库文件设置
 * @date 10/03/2025
 * @export
 */
export function knowledgeBaseFileSetting(data: KnowledgeBaseFileSetting) {
  return defHttp.post({
    url: Api.knowledgeBaseFileSetting,
    data,
  });
}

/**
 * @description 获取文件分享列表
 * @date 10/03/2025
 * @export
 */
export function knowledgeBaseFileShareList(data: KnowledgeBaseFileShareListData) {
  return defHttp.post<IResData<KnowledgeBaseFileShareListResult>>({
    url: Api.knowledgeBaseFileShareList,
    data,
  });
}


/**
 * @description 获取会员信息
 * @date 17/03/2025
 * @export
 */
export function getMemberInfo() {
  return defHttp.get<MemberInfoResult>({
    url: Api.getMemberInfo,
  });
}

/**
 * @description 设置启用或禁用
 * @date 17/03/2025
 * @export
 * @param {0 | 1} enable - 0表示禁用，1表示启用
 */
export function setMemberEnable(enable: 0 | 1) {
  return defHttp.post({
    url: `${Api.setEnable}/${enable}`,
  });
}

